package org.clever.sharding.jdbc.aop;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.After;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.clever.sharding.jdbc.annotation.Sharding;
import org.springframework.stereotype.Component;

/**
 * Created by Administrator on 2018/12/5.
 */
@Aspect
@Component
@Slf4j
public class ShardingAspect {

    @Before(value = "@annotation(sharding)")
    protected void beforeDsIntoSharding(JoinPoint joinPoint, Sharding sharding) {
        ShardingHolder.setSharding();
    }

    @After(value = "@annotation(sharding)")
    protected void afterDsIntoSharding(JoinPoint joinPoint, Sharding sharding) {
        ShardingHolder.clear();
    }
}
